<?php
declare (strict_types = 1);

namespace app\model;

class Code extends BaseModel
{
    protected $name = 'code';
    
    // 生成赋码
    public static function generateCode($length = 8)
    {
        $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
        $code = '';
        for ($i = 0; $i < $length; $i++) {
            $code .= $chars[mt_rand(0, strlen($chars) - 1)];
        }
        return $code;
    }
    
    // 生成二维码
    public function generateQrcode($content)
    {
        $qrcode = new \QRCode();
        $qrcode->setText($content);
        $qrcode->setSize(300);
        $qrcode->setMargin(10);
        $qrcode->setErrorCorrectionLevel('H');
        
        // 生成二维码图片
        $filename = 'qrcode/' . uniqid() . '.png';
        $qrcode->writeFile(public_path() . $filename);
        
        return $filename;
    }
} 